package com.zhaopin.netty.tianyuan;


import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;


/**
 * Created by TianYuan on 2018/1/5.
 */
public class WebSocketChannelInitializer extends ChannelInitializer<Channel> {

    public static final ServiceHandler API_LOGIC_HANDLER = new ServiceHandler();
    public static final PokerCodec API_MESSAGE_CODEC = new PokerCodec();


    @Override
    protected void initChannel(Channel ch) throws Exception {
        ch.pipeline().addLast("httpcodec", new HttpServerCodec());
        ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));
        ch.pipeline().addLast("handshake", new WebSocketServerProtocolHandler("/", "", true));
        ch.pipeline().addLast("com/yt/ddz/codec",API_MESSAGE_CODEC);

        ch.pipeline().addLast(NettyExecutorGroup.getInstance().getExecutorGroup(), API_LOGIC_HANDLER);
    }
}
